import logging
import time

import pytest


class Test:

    @pytest.mark.parametrize('setup_teardown', [None], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1、长按图库服务卡片，点击移除')
        device.refresh_layout()
        form_component = device.get_element_by_type('FormComponent')
        if not form_component:
            camera = device.get_element_by_text('相机')
            cx, cy = device.center_of_element(camera)
            device.long_click(cx, cy - 50)
            device.refresh_layout()
            card_center = device.get_element_by_text('卡片中心')
            device.click_element(card_center)
            device.wait(1)
            device.refresh_layout()
            camera_card = device.get_element_by_text('相机')
            device.click_element(camera_card)
            device.refresh_layout()
            device.click_element(device.get_element_by_text('添加到桌面'))
            device.refresh_layout()
            form_component = device.get_element_by_type('FormComponent')
        device.long_click_element(form_component)
        device.refresh_layout()
        device.click_element(device.get_element_by_text('移除'))
        device.refresh_layout()
        device.click_element(device.get_element_by_text('移除'))
        logging.info('步骤2、长按相机服务卡片，点击移除')
        device.refresh_layout()
        form_component = device.get_element_by_type('FormComponent')
        if form_component:
            device.long_click_element(form_component)
            device.refresh_layout()
            device.click_element(device.get_element_by_text('移除'))
            device.refresh_layout()
            device.click_element(device.get_element_by_text('移除'))
            device.refresh_layout()
        logging.info('预期结果1&2、相机服务卡片从桌面移除')
        device.assert_type_exist('FormComponent', expect=False)
